package com.apes.fn.crm.customComplain;

import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * 功能： 客诉单
 *
 * @author BieBi
 * @create 2018-7-11 11:37:08
 */
public interface FnCustomComplainRepository extends CustomRepository<FnCustomComplain, String> {

    /***
     * 功能： 查询停单单据
     * @return
     */
    @Query(" select t from FnCustomComplain t WHERE t.stopId is not null and t.startDate < CURRENT_DATE and t.state = 'disposing' and t.active = false ")
    List<FnCustomComplain> findCustomComplainRestart();


    /***
     * 功能： 查询某个客户客诉总量
     */
    @Query("select count(t) from FnCustomComplain t where t.deleteDate is null and t.customComplainType.description = '投诉' and t.customerExpand.mobile = :mobile and t.company.id = :companyId")
    int countCustomComplain(@Param("mobile") String mobile, @Param("companyId") String companyId);


    List<FnCustomComplain> findAllByOriginIsNullAndResponsiblePersonsIsNotNullOrComplainPersonsIsNotNull();

    @Query(value = " select A.ID as id, A.vip_id as vip_id from  fn_custom_complain A WHERE 1 = 1", nativeQuery = true)
    List<Map> queryData();
}
